<template>
  <div class="introduce_wrap safe">
    <div class="banner_wrap">
      <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
        <van-swipe-item v-for="(item, index) in ad.bannerLink" :key="index">
          <div class="banner_item">
            <van-image fit="cover" :src="item.link" />
          </div>
        </van-swipe-item>
      </van-swipe>
    </div>
    <div class="introduction">
      <div v-html="voteInfo.introduction"></div>
    </div>
    <footer-logo></footer-logo>
  </div>
</template>
<script>
import { mapGetters } from "vuex";
import footerLogo from "@/components/footerLogo";
import { LgetItem } from "@/utils/storage";
import { wx,wxInit } from "@/utils/jssdkInit";
import cfg from "@/config";
export default {
  components: {
    footerLogo,
  },
  data() {
    return {
      voteInfo: {},
      voteId:LgetItem('voteId'),
    };
  },
  computed: {
    ...mapGetters("configs", {
      ad: "ad",
      share:'share'
    }),
  },
  created() {
    this.getVoteInfo();
  },
  mounted(){
    this.shareFn(this.share)
  },
  methods: {
    shareFn(share) {
      console.log(share)
      this.$nextTick(() => {
        wxInit()
          .then(() => {
            wx.updateAppMessageShareData({
              //分享到朋友
              title: share.title, // 分享标题
              desc: share.context, // 分享描述
              link: window.location.href.indexOf('?') != -1?window.location.href:`${window.location.href}?id=${LgetItem("voteId")}`, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
              imgUrl:share.imageLink?share.imageLink:cfg.shareImg, // 分享图标
              success: () => {
                console.log("分享成功");
              },
            });
            wx.updateTimelineShareData({
              //分享到朋友圈
              title: share.title, // 分享标题
              link: window.location.href.indexOf('?') != -1?window.location.href:`${window.location.href}?id=${LgetItem("voteId")}`, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
              imgUrl:share.imageLink?share.imageLink:cfg.shareImg, // 分享图标
              success: function () {
                console.log("分享成功");
              },
            });
          })
          .catch((err) => {
            console.log(err,'err');
          });
        //   toast.clear();
      });
    },
    getVoteInfo() {
      this.$api("vote.getVoteInfo", {
        id: this.voteId,
      }).then((res) => {
        console.log(res);
        this.voteInfo = res;
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.introduce_wrap {
  width: 100%;
  min-height: 100vh;
  position: relative;
  font-size: 14px;
  .banner_wrap {
    .banner_item {
      font-size: 0;
      ::v-deep.van-image {
        width: 100%;
        height: 200px;
      }
    }
  }
  .introduction {
    background-color: #fff;
    padding: 5px;
    border-radius: 4px;
    margin: 10px 10px 0;
  }
}
</style>